//给出一个升序排序的链表，删除链表中的所有重复出现的元素，只保留原链表中只出现一次的元素。

public class Solution {
    public class ListNode {
        int val;
        ListNode next = null;
        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode deleteDuplicates (ListNode head) {
        if(head == null ){
            return null;
        }
        ListNode res = new ListNode(0);
        //在链表前加一个表头
        ListNode cur = res;
        res.next = head;
        while(cur.next != null && cur.next.next != null){
            if(cur.next.val == cur .next.next.val){
                int tmp = cur.next.val;
                //跳过重复链表
                while(cur.next != null && cur.next.val == tmp){
                    cur.next = cur.next.next;
                }
            }else{
                cur = cur.next;
            }
            }
        return res.next;
        }
}
